from datetime import datetime

from app import db
class AuthInfo(db.Model):
    __tablename__ = 'auth_info'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    auth_code = db.Column(db.String(255), nullable=True, comment='授权码')
    start_time = db.Column(db.DateTime, nullable=True, comment='开始时间')
    end_time = db.Column(db.DateTime, nullable=True, comment='结束时间')
    bind_ip = db.Column(db.String(255), nullable=True, comment='绑定的IP')
    status = db.Column(db.Integer, nullable=True, comment='状态')
    create_time = db.Column(db.DateTime, default=datetime.utcnow, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment='更新时间')
    page_download_count = db.Column(db.Integer, nullable=True, comment='页面下载次数')
    auth_scope = db.Column(db.Integer, nullable=True, comment='授权范围')

    def to_json(self):
        return {
            'id': self.id,
            'auth_code': self.auth_code,
            'start_time': self.start_time,
            'end_time': self.end_time,
            'bind_ip': self.bind_ip,
            'status': self.status,
            'create_time': self.create_time,
            'update_time': self.update_time,
            'page_download_count': self.page_download_count,
            'auth_scope': self.auth_scope
        }